package codetop.kuaishou.T129;

import util.TreeNode;

/**
 * @Author: 18362
 * @Create: 2022-09-13 22:05:39 星期二
 */
class Solution {

    private int sum = 0;

    public int sumNumbers(TreeNode root) {
        tranverse(root, 0);
        return sum;
    }

    private void tranverse(TreeNode root, int num) {
        if (root == null)
            return;
        num = num * 10 + root.val;
        if (root.left == null && root.right == null) {
            sum += num;
            return;
        }
        tranverse(root.left, num);
        tranverse(root.right, num);
    }
}